package com.lvtulife.common.web.util.search;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Mybatis 查询参数封装类
 */
public class SearchParams implements Serializable {
    private Map<String, Object> params = new HashMap<String, Object>(0);// 条件参数
    private List<Order> orders = new ArrayList<Order>(0);

    /**
     * 指定自定义的Mybatis配置文件的名称
     * 例如 传入 MemClassIbatis 会读取 MemClassIbatis.xml
     */
    private String configName;

    /**
     * 指定获取哪个预制参数(查询表和查询字段)
     * 需要 SelectSql 和 JoinSql 定义成一致，参数为空时默认取 “all”
     */
    private String param;

    /**
     * Mybatis版本，会读取Mybatis相关配置
     *
     * @param configName
     */
    public SearchParams(String configName) {
        this.configName = configName;
    }

    /**
     * Mybatis版本，会读取Mybatis相关配置
     *
     * @param configName
     */
    public SearchParams(String configName, String param) {
        this.configName = configName;
        this.param = param;
    }

    public void addParam(String param, Object val) {
        params.put(param, val);
    }

    public void addOrderAsc(String order) {
        orders.add(new Order(order));
    }

    public void addOrderDesc(String order) {
        orders.add(new Order(order, false));
    }

    public String getConfigName() {
        return configName;
    }

    public String getparam() {
        return param;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public List<Order> getOrders() {
        return orders;
    }
}
